#include <bits/stdc++.h>
using namespace std;
const int maxn = 12 * 2000;
int N, V;
int rv[maxn], rw[maxn], idx;
int dp[maxn];
int main() {
  cin >> N >> V;
  for (int i = 1; i <= N; ++i) {
    int s, v, w;
    cin >> v >> w >> s;
    int k = 1;
    while (s - k > 0) {
      idx++;
      rv[idx] = k * v;
      rw[idx] = k * w;
      s -= k;
      k *= 2;
    }
    if (s > 0) {
      idx++;
      rv[idx] = s * v;
      rw[idx] = s * w;
    }
  }
  for (int i = 1; i <= idx; ++i) {
    for (int j = V; j >= rv[i]; --j) {
      dp[j] = max(dp[j], dp[j - rv[i]] + rw[i]);
    }
  }
  cout << dp[V] << endl;
}
